package com.chart.chart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chart.chart.domian.ChartConfigs;
import com.chart.chart.domian.ChartOrders;
import com.chart.chart.domian.vo.ChartConfigsInterface;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 用户表 数据层
 * 
 * @author ruoyi
 */
@Mapper
public interface ChartOrdersMapper extends BaseMapper<ChartOrders>
{


    @Update("update chart_orders set status = 1 where order_num = #{orderNum}")
    boolean updateOrderStatu(String orderNum);

    @Select("SELECT u.user_id, u.user_name, u.email,u.phonenumber," +
            "o.create_time, o.order_id, o.order_num, o.total_price " +
            "FROM sys_user u " +
            "LEFT JOIN chart_orders o ON u.user_id = o.user_id " +
            "WHERE u.phonenumber LIKE CONCAT('%', #{phonenumber}, '%')")
    List<ChartOrders> findUserOrders(String userName);

    @Select("SELECT co.*, su.phonenumber, co.total_price / 100 AS total_price_in_yuan " +
            "FROM chart_orders co " +
            "LEFT JOIN sys_user su ON co.user_id = su.user_id " +
            "WHERE co.status = 1 " +
            "ORDER BY co.create_time DESC")
    List<ChartOrders> queryOrder();


    // 统计用户的订单数量
    @Select("SELECT COUNT(*) FROM chart_orders WHERE user_id = #{userId} AND status = #{status}")
    int selectCounts(@Param("userId") Long userId, @Param("status") int status);

}

